package org.act.bpel2automata.views.model;

import org.act.BPEL2Automata.automata.module.Message;
import org.act.BPEL2Automata.automata.module.State;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

public class Model4PropertyView implements IPropertySource {
	private static final String CATEGORY_MESSAGE = "MESSAGE";
	private static final String CATEGORY_STATE = "STATE";
	
	private static final String ID_MES_PARTNERLINK = "Mes_PartnerLink";
	private static final String ID_MES_PORTTYPE = "Mes_PortType";
	private static final String ID_MES_OPERATION = "Mes_Operation";
	private static final String ID_MES_MESSAGETYPE = "Mes_MessageType";
	private static final String ID_MES_DIRECTION = "Mes_Direction";
	
	private static final String ID_STA_SOURCELIST = "Sta_SourceList";
	private static final String ID_STA_TARGETLIST = "Sta_TargetList";
	
	
	private Message message = null;
	private State state = null;
	
	public Model4PropertyView(Object object){
		if(object instanceof Message){
			this.message = (Message)object;
		}
		else
		if(object instanceof State){
			this.state = (State)object;
		}
	}
	
	
	@Override
	public Object getEditableValue() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IPropertyDescriptor[] getPropertyDescriptors() {
		// TODO Auto-generated method stub
		IPropertyDescriptor[] descriptors = new IPropertyDescriptor[]{
				new TextPropertyDescriptor(ID_MES_PARTNERLINK, "PartnerLink"),
				new TextPropertyDescriptor(ID_MES_PORTTYPE, "PortType"),
				new TextPropertyDescriptor(ID_MES_OPERATION, "Operation"),
				new TextPropertyDescriptor(ID_MES_MESSAGETYPE, "MessageType"),
				new TextPropertyDescriptor(ID_MES_DIRECTION, "Direction"),
				
				new TextPropertyDescriptor(ID_STA_SOURCELIST, "SourceList"),
				new TextPropertyDescriptor(ID_STA_TARGETLIST, "TargetList")
		};
		
		PropertyDescriptor p = null;
		
		for(int i = 0; i < 5; i++){
			p = (PropertyDescriptor)descriptors[i];
			p.setCategory(CATEGORY_MESSAGE);
		}
		
		for(int i = 0; i < 2; i++){
			p = (PropertyDescriptor)descriptors[i];
			p.setCategory(CATEGORY_STATE);
		}
		
		return descriptors;
	}

	@Override
	public Object getPropertyValue(Object id) {
		// TODO Auto-generated method stub
		
		if(id.equals(ID_MES_PARTNERLINK)){
			return this.message.getPartnerLink().getName();
		}
		else
		if(id.equals(ID_MES_PORTTYPE)){
			return this.message .getPortType().getName();
		}
		else
		if(id.equals(ID_MES_OPERATION)){
			return this.message.getOperation().getName();
		}
		else
		if(id.equals(ID_MES_MESSAGETYPE)){
			return this.message.getMessageType().getName();
		}
		else
		if(id.equals(ID_MES_DIRECTION)){
			return this.message.getDirection();
		}
		
		else
		if(id.equals(ID_STA_SOURCELIST)){
			return this.state.getSourceList().toString();
		}
		else
		if(id.equals(ID_STA_TARGETLIST)){
			return this.state.getTargetList().toString();
		}
		
		return null;
	}

	@Override
	public boolean isPropertySet(Object id) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void resetPropertyValue(Object id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setPropertyValue(Object id, Object value) {
		// TODO Auto-generated method stub
		
	}

}
